package com.polaris.live.resp.back_resp

import com.polaris.live.common.util.JsonUtils

/**
 *
 * @author Created by 天晴 on 2024/5/27 17:36
 * @since 1.0.0
 **/
data class UserBackpackGiftResp(
    /**
     * 道具数量
     */
    val amount: Long,

    /**
     * 背包id
     */
    val backpackId: Long,

    /**
     * 背包类型
     *
     * 2 - 礼物
     * 3 - 道具
     */
    val backpackType: Long,

    /**
     * 相关的类型对象数据
     *
     * 礼物 - GiftVo
     * 道具 - UserConsumableVo
     */
    val content: String,

    /**
     * 道具描述
     */
    val description: String? = null,

    /**
     * 道具过期时间
     */
    val expiredTime: String? = null,
) {
    private var gift: GiftBean? = null
    private var mUserBackpackConsumableResp: UserBackpackConsumable2Resp? = null

    fun getGiftBean(): GiftBean? {
        if (gift != null) {
            return gift
        }
        return if (backpackType == 2L) {
            gift = JsonUtils.fromJson<GiftBean>(content)
            gift
        } else {
            null
        }
    }

    fun getGiftBeanNoNull(): GiftBean {
        return getGiftBean() ?: GiftBean(
            -1,
            "",
            -1,
            0L,
            "",
            null,
            null,
            0,
            0,
            mutableListOf(),
            0,
            null,
            null
        )
    }

    fun getUserBackpackConsumableResp(): UserBackpackConsumable2Resp? {
        if (mUserBackpackConsumableResp != null) {
            return mUserBackpackConsumableResp
        }
        return if (backpackType == 3L) {
            mUserBackpackConsumableResp = JsonUtils.fromJson<UserBackpackConsumable2Resp>(content)
            mUserBackpackConsumableResp
        } else {
            null
        }

    }

}